home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / Hydra11s.lha / HBBS / Source / Utils / HBBSMutliTop / Main.c < prev    next >
C/C++ Source or Header  |  1996-06-25  |  11KB  |  532 lines

  1. /*
  2.  
  3.   My brother is writing this, I have no idea how it works, or what state it is in..
  4.  
  5.   It is supposed to be an HBBS clone of the brilliant MultiTop for AmiExpress...
  6.  
  7.  
  8. */
  9.  
  10. /* **** HBBS Door Code****************************************************** */
  11.  
  12. /*
  13.   DoorName
  14.   ========
  15.  
  16.     HBBSMultiTop
  17.  
  18.   Version
  19.   =======
  20.  
  21.     1.0, release  1, 26/12/1995
  22.  
  23.   Options
  24.   =======
  25.  
  26.     N_ND->ActiveDoor->SystemOptions
  27.     -------------------------------
  28.  
  29.  
  30.  
  31.     Command Line Arguments
  32.     ----------------------
  33.  
  34.   ToDo
  35.   ====
  36.  
  37.  
  38.  
  39.  
  40. */
  41.  
  42. /* **** Includes *********************************************************** */
  43.  
  44. #include <exec/types.h>
  45. #include <exec/memory.h>
  46. #include <dos/dos.h>
  47. #include <clib/exec_protos.h>
  48. #include <clib/dos_protos.h>
  49. #include <clib/alib_protos.h>
  50.  
  51. #include <stdlib.h>
  52. #include <string.h>
  53. #include <stdio.h>
  54. #include <ctype.h>
  55. #include <time.h>
  56.  
  57. #include <HBBS/ANSI_Codes.h>
  58. #include <HBBS/Defines.h>
  59. #include <HBBS/types.h>
  60. #include <HBBS/Access.h>
  61. #include <HBBS/structures.h>
  62. #include <HBBS/hbbscommon_protos.h>
  63. #include <HBBS/hbbscommon_pragmas.h>
  64. #include <HBBS/Hbbsnode_protos.h>
  65. #include <HBBS/Hbbsnode_pragmas.h>
  66.  
  67. /* **** Definitions ******************************************************** */
  68.  
  69. #define BENS_HEADER "+------------------------------------------------------+\r\n|            Zippy Search V1 by Ben Clifton            |\r\n|           (C) 1995 Ruby Knight Productions           |\r\n+------------------------------------------------------+\r\n"
  70.  
  71. /* **** Variables ********************************************************** */
  72.  
  73.  
  74. struct Library *HBBSCommonBase  = NULL;
  75. struct Library *HBBSNodeBase    = NULL;
  76.  
  77. struct BBSGlobalData *BBSGlobal = NULL;
  78. struct NodeData *N_ND           = NULL;
  79. int    N_NodeNum                = -1;
  80.  
  81. long __stack=16*1024; // increse this in 4k incrments if you suffer from
  82.                       // random/suprious crashings after or during the running
  83.                       // of your door.
  84.  
  85. int    gargc;         // these are just copies of main()'s argc and argv..
  86. char   **gargv;
  87.  
  88. ULONG CurrentFileNumber = 0;
  89. ULONG LinesOutput = 0;
  90.  
  91. BOOL GBL_Error = FALSE;
  92.  
  93. struct List *UserNames;
  94. struct List *ULFiles;
  95. struct List *ULBytes;
  96. struct List *DLFiles;
  97. struct List *DLBytes;
  98.  
  99. char tmpstr[BIG_STR];
  100.  
  101. /* **** Functions ********************************************************** */
  102.  
  103.  
  104. #ifdef __SASC
  105. int CXBRK(void) { return(0); }
  106. int _CXBRK(void) { return(0); }
  107. void chkabort(void) {}
  108. #endif
  109.  
  110. static VOID cleanup(ULONG num)
  111. {
  112.   if (HBBSCommonBase)
  113.   {
  114.     HBBS_CleanUpCommon();
  115.     CloseLibrary (HBBSCommonBase);
  116.   }
  117.  
  118.   if (num) printf("Door Error = %d\n",num);
  119.  
  120.   exit(0);
  121. }
  122.  
  123. static VOID init( void )
  124. {
  125.   if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  126.   {
  127.     cleanup(1);
  128.   }
  129.  
  130.   if (!(HBBS_InitCommon()))
  131.   {
  132.     cleanup(2);
  133.   }
  134. }
  135.  
  136. void FM_strFNcpy( char *in, char *out, int start, int num )
  137. {
  138.   int loop, i;
  139.  
  140.   for( i=0, loop = start; (loop < num+start) && (in[loop]); loop++, i++ ) out[i] = in[loop];
  141.   out[i]=0;
  142. }
  143.  
  144. void FM_RemoveCR( char *s )
  145. {
  146.   if( s[0] )
  147.   {
  148.     if( (s[strlen(s)-1] == '\n')|| (s[strlen(s)-1] == '\r' ) )
  149.       s[strlen(s)-1] = 0;
  150.     if( (s[strlen(s)-1] == '\n')|| (s[strlen(s)-1] == '\r' ) )
  151.       s[strlen(s)-1] = 0;
  152.   }
  153. }
  154.  
  155. void strpad(char *buffer, int requiredlen, UBYTE PadChar)
  156. {
  157.   int many;
  158.   int loop;
  159.   int clen=strlen(buffer);
  160.  
  161.   if (clen<requiredlen)
  162.   {
  163.     many=requiredlen-clen;
  164.     for (loop=0;loop<=many;loop++) buffer[clen+loop]=PadChar;
  165.     buffer[requiredlen]=0;
  166.   }
  167. }
  168.  
  169. struct List *ReadTextFile( char *filename )
  170. {
  171.   return( HBBS_LoadFile( filename ));
  172. }
  173.  
  174. //  tmpstr="my mother was a boar"
  175.  
  176. //  replace(tmpstr,tmpstr,"boar","whoar");
  177.  
  178. #define SORT_UPLOADEDBYTES     0
  179. #define SORT_UPLOADEDFILES     1
  180. #define SORT_DOWNLOADEDBYTES   2
  181. #define SORT_DOWNLOADEDFILES   3
  182. #define SORT_CALLS             4
  183. #define SORT_MESSAGES          5
  184.  
  185. void CheckForConfigs( struct List *data )
  186. {
  187.   short where;
  188.  
  189.   for( ptr = data->lh_Head; ptr->ln_Succ; ptr = ptr->ln_Succ )
  190.   {
  191.     if( iposition( "SORT=", ptr->ln_Name ) >= 0 )
  192.     {
  193.       if( iposition( "UPLOADEDBYTES", ptr->ln_Name ) >= 0 )
  194.       {
  195.         SortBy = SORT_UPLOADEDBYTES;
  196.       }
  197.       else
  198.       if( iposition( "UPLOADEDFILES", ptr->ln_Name ) >= 0 )
  199.       {
  200.         SortBy = SORT_UPLOADEDFILES;
  201.       }
  202.       else
  203.       if( iposition( "DOWNLOADEDBYTES", ptr->ln_Name ) >= 0 )
  204.       {
  205.         SortBy = SORT_DOWNLOADEDBYTES;
  206.       }
  207.       else
  208.       if( iposition( "DOWNLOADEDFILES", ptr->ln_Name ) >= 0 )
  209.       {
  210.         SortBy = SORT_DOWNLOADEDFILES;
  211.       }
  212.       else
  213.       if( iposition( "CALLS", ptr->ln_Name ) >= 0 )
  214.       {
  215.         SortBy = SORT_CALLS;
  216.       }
  217.       else
  218.       if( iposition( "MESSAGES", ptr->ln_Name ) >= 0 )
  219.       {
  220.         SortBy = SORT_MESSAGES;
  221.       }
  222.       /* Do not display this line so remove it from the list! */
  223.       FreeStr(ptr->ln_Name);
  224.       Remove(ptr);
  225.       FreeVec(ptr);
  226.     }
  227.   }
  228. }
  229.  
  230. #define KEY_UB 0
  231. #define KEY_UK 1
  232. #define KEY_UM 2
  233. #define KEY_UF 3
  234. #define KEY_DB 4
  235. #define KEY_DK 5
  236. #define KEY_DM 6
  237. #define KEY_DF 7
  238. #define KEY_UN 8
  239. #define KEY_CS 9
  240. #define KEY_MS 10
  241. #define KEY_DF 11
  242. #define KEY_LT 12
  243. #define KEY_ST 13
  244.  
  245. int ConvertKeyword( char *keyword )
  246. {
  247.   if( stricmp( "UB", keyword ) )
  248.     return( KEY_UB );
  249.   else
  250.   if( stricmp( "UK", keyword ) )
  251.     return( KEY_UK );
  252.   else
  253.   if( stricmp( "UM", keyword ) )
  254.     return( KEY_UM );
  255.   else
  256.   if( stricmp( "UF", keyword ) )
  257.     return( KEY_UF );
  258.   else
  259.   if( stricmp( "DB", keyword ) )
  260.     return( KEY_DB );
  261.   else
  262.   if( stricmp( "DK", keyword ) )
  263.     return( KEY_DK );
  264.   else
  265.   if( stricmp( "DM", keyword ) )
  266.     return( KEY_DM );
  267.   else
  268.   if( stricmp( "DF", keyword ) )
  269.     return( KEY_DF );
  270.   else
  271.   if( stricmp( "UN", keyword ) )
  272.     return( KEY_UN );
  273.   else
  274.   if( stricmp( "CS", keyword ) )
  275.     return( KEY_CS );
  276.   else
  277.   if( stricmp( "MS", keyword ) )
  278.     return( KEY_MS );
  279.   else
  280.   if( stricmp( "DF", keyword ) )
  281.     return( KEY_DF );
  282.   else
  283.   if( stricmp( "LT", keyword ) )
  284.     return( KEY_LT );
  285.   else
  286.   if( stricmp( "ST", keyword ) )
  287.     return( KEY_ST );
  288. }
  289.  
  290. void DoReplacement( string, pos, length, centre, char *type )
  291. {
  292.   char replacement[BIG_STR], char *newstring;
  293.  
  294.   switch( ConvertKeyword( type )
  295.   {
  296.     case KEY_UB:
  297.       break;
  298.     case KEY_UK:
  299.       break;
  300.     case KEY_UM:
  301.       break;
  302.     case KEY_UF:
  303.       break;
  304.     case KEY_DB:
  305.       break;
  306.     case KEY_DK:
  307.       break;
  308.     case KEY_DM:
  309.       break;
  310.     case KEY_DF:
  311.       break;
  312.     case KEY_UN:
  313.       break;
  314.     case KEY_CS:
  315.       break;
  316.     case KEY_MS:
  317.       break;
  318.     case KEY_DF:
  319.       break;
  320.     case KEY_LT:
  321.       break;
  322.     case KEY_ST:
  323.       strcpy( replacement, "This is a test!" );
  324.       if( newstring = AllocVec( BIG_STR, MEMF_PUBLIC|MEMF_CLEAR ) )
  325.       {
  326.         replace(newstring, string, actualcommand, replacement);
  327.         ptr->ln_Name = newstring;
  328.         FreeVec( string );
  329.       }
  330.       break;
  331.   }
  332. }
  333.  
  334. LONG CreateOutput( struct List *data, struct List *outdata )
  335. {
  336.   struct Node *ptr;
  337.   char *FieldStart, *fptr;
  338.   BOOL Exit;
  339.   char KeyWorkType[5];
  340.   char tmp[5];
  341.   int pos, length, centre = JUST_RIGHT, num;
  342.  
  343.   for( ptr = data->lh_Head; ptr->ln_Succ; ptr = ptr->ln_Succ )
  344.   {
  345.     fptr = ptr->ln_Name;
  346.     while( FieldStart = FindKeywordStart( fptr ) )
  347.     {
  348.       //             User No. -=left .centre
  349.       // Command "%<pos><center><length><keyword> Example %01-10UN
  350.  
  351.       Exit = FALSE;
  352.       for( i=1; (i<7)&&(!Exit); i++ )
  353.       {
  354.         if( (FieldStart[i] > 'A') && (FieldStart[i] < 'Z')
  355.         {
  356.           Exit = TRUE;
  357.         }
  358.       }
  359.  
  360.       // %nncnncc  6
  361.       // %cnncc    4
  362.       // %cc       1
  363.       // %nncc     3
  364.  
  365.       if( i <= 6 )
  366.       {
  367.         KeyWorkType[0] = FieldStart[i];
  368.         KeyWorkType[1] = FieldStart[i+1];
  369.         KeyWorkType[2] = 0;
  370.  
  371.  
  372.         if( i > 1 )
  373.         {
  374.           if( i == 3 )
  375.           {
  376.             tmp[0] = FieldStart[1];
  377.             tmp[1] = FieldStart[2];
  378.             tmp[2] = 0;
  379.             pos = atoi( tmp );
  380.           }
  381.           else
  382.           {
  383.             if( i==4 )
  384.             {
  385.               num = 1;
  386.             }
  387.             else
  388.             {
  389.               num = 3;
  390.             }
  391.  
  392.             switch( FieldStart[num] )
  393.             {
  394.               case '-':
  395.                 centre = JUST_LEFT;
  396.                 break;
  397.               case '.':
  398.                 centre = JUST_CENTRE;
  399.                 break;
  400.               default:
  401.                 centre = JUST_RIGHT;
  402.                 break;
  403.             }
  404.             tmp[0] = FieldStart[num+1];
  405.             tmp[1] = FieldStart[num+2];
  406.             tmp[2] = 0;
  407.             length = atoi( tmp );
  408.             if( num > 2 )
  409.             {
  410.               tmp[0] = FieldStart[1];
  411.               tmp[1] = FieldStart[2];
  412.               tmp[2] = 0;
  413.               pos = atoi( tmp );
  414.             }
  415.           }
  416.         }
  417.  
  418.         if( (FieldStart[1] > '0') && (FieldStart[1] > '9') && (FieldStart[2] > '0') && (FieldStart[2] > '9'))
  419.         {
  420.           tmp[0] = FieldStart[1];
  421.           tmp[1] = FieldStart[2];
  422.           tmp[2] = 0;
  423.           pos = atoi( tmp );
  424.         }
  425.         switch( FieldStart[3] )
  426.         {
  427.           case '.':
  428.           case '-':
  429.             if( i
  430.             break;
  431.         }
  432.  
  433.         DoReplacement( ptr->ln_Name, pos, length, centre, KeyWorkType );
  434.       }
  435.     }
  436.   }
  437. }
  438.  
  439. void SaveData( char *filename, struct List *data )
  440. {
  441.   HBBS_SaveFile( filename, data );
  442. }
  443.  
  444. /* **** UtilMain *********************************************************** */
  445.  
  446. void UtilMain( void )
  447. {
  448.   char outfilename[BIG_STR], infilename[BIG_STR];
  449.   LONG ConfNum;
  450.   LONG UserFlags;
  451.   struct List *inputfiledata;
  452.  
  453.   if( gargc < 2 )
  454.   {
  455.     Printf( "Teppic HBBSTopStat V1.0 by Ben Clifton\n"
  456.             "   (C)1995 Ruby Knight Productions\n"
  457.             "--------------------------------------\n"
  458.           );
  459.   }
  460.   else
  461.   {
  462.     switch( gargv[1][0] )
  463.     {
  464.       case '?':
  465.         Printf("\n"
  466.                "Usage : HBBSTopStat <design> <output> [<confnum>]\n"
  467.                "\n"
  468.                "  design  - Full path to your design file.\n"
  469.                "  output  - Full path to your output file.\n"
  470. //               "  sortby  - Field by which to sort UserList\n"
  471. //               "             UF Top File Uploaders (default)\n"
  472. //               "             UB Top Bytes Uploaders\n"
  473. //               "             DL Top File Downloaders\n"
  474. //               "             DB Top Bytes Downloaders\n"
  475.                "  confnum - Conference Number for data to be pulled from.\n"
  476.               );
  477.         break;
  478.       default:
  479.         strcpy( infilename, gargv[1] );
  480.  
  481.         if( gargc < 3 )
  482.         {
  483.           outfilename[0] = 0;
  484.         }
  485.         else
  486.         {
  487.           strcpy( outfilename, gargv[2] );
  488.         }
  489.  
  490.         if( gargc < 4 )
  491.         {
  492.           ConfNum = 1L;
  493.         }
  494.         else
  495.         {
  496.           ConfNum = atol( gargv[3] );
  497.         }
  498.  
  499.  
  500.         inputfiledata = ReadTextFile( infilename );
  501.         if( !GBL_Error )
  502.         {
  503.           CheckForConfigs( inputfiledata );
  504.           CreateDataLists( UserFlags );
  505.           if( !GBL_Error )
  506.           {
  507.             outputfiledata = CreateOutput( inputfiledata );
  508.             if( !GBL_Error )
  509.             {
  510.               SaveData( outfilename, outputfiledata );
  511.             }
  512.           }
  513.         }
  514.         break;
  515.     }
  516.   }
  517. }
  518.  
  519. int main(int argc,char **argv)
  520. {
  521.   gargc=argc;
  522.   gargv=argv;
  523.  
  524.   init();
  525.  
  526.   UtilMain();
  527.  
  528.   cleanup(0);
  529. }
  530.  
  531. /* **** End Of File ******************************************************** */
  532.